import Vue from 'vue'

import ElementUI from 'element-ui';
import '../theme/index.css'
Vue.use(ElementUI);

import router from './router/index'  // 自动的扫描router下的index
// 通过 beforeEach 设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})
// axios响应拦截器
axios.interceptors.response.use((response) => {
  if (response.data == "noLoginOfUser"){
    router.push( '/loginRegistrationPage/login').then(r => {})
    //终止请求
    return Promise.reject()
  }else if(response.data == "noLoginOfAdmin"){
    router.push( '/adminPage/loginCode').then(r => {})
    //终止请求
    return Promise.reject()
  } else if (response.data == "disable") {
    console.log(response.data)
    this.$message.warning("抱歉，该功能正在升级中，尽请期待...")
    //终止请求
    return Promise.reject()
  }else{
    return response
  }
}, function (error) {
  this.$message.error("服务器异常")
  return Promise.reject()
});


import axios from 'axios'
import VueAxios from 'vue-axios'
axios.defaults.withCredentials = true
Vue.use(VueAxios, axios)

import App from './App'
import  './assets/css/icon-biaoqing.css';
import  './assets/css/icon-font.css';
import  './assets/css/icon-font2.css';
import  './assets/css/normalize.css';

import * as echarts from 'echarts';
//需要挂载到Vue原型上
Vue.prototype.$echarts = echarts

import moment from 'moment'
// 定义一个全局过滤器实现日期格式化
Vue.filter('formatDate', function (timestamp) {
  // utcOffset(0) 设置时区为北京时间
  return moment(timestamp).format('YYYY-MM-DD HH:mm:ss')
})


// v-viewer插件,放大图片
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
Vue.use(Viewer)
Viewer.setDefaults({
  Options: {
    'inline': true,
    'button': true,
    'navbar': true,
    'title': true,
    'toolbar': true,
    'tooltip': true,
    'movable': true,
    'zoomable': true,
    'rotatable': true,
    'scalable': true,
    'transition': true,
    'fullscreen': true,
    'keyboard': true,
    'url': 'data-source'
  }
})

//markdown编辑器
import VueMarkdownEditor from '@kangc/v-md-editor';
import '@kangc/v-md-editor/lib/style/base-editor.css';
import vuepressTheme from '@kangc/v-md-editor/lib/theme/vuepress.js';
import '@kangc/v-md-editor/lib/theme/style/vuepress.css';
import Prism from 'prismjs';
import el from "element-ui/src/locale/lang/el";
VueMarkdownEditor.use(vuepressTheme, {
  Prism,
});
Vue.use(VueMarkdownEditor);


Vue.config.productionTip = false

import i18n from './lang/index'

/* eslint-disable no-new */
// new Vue({
//   router,  // 配置路由
//   i18n,
//   render: h => h(App)
// }).$mount('#app');

new Vue({
  el: '#app',
  router,  // 配置路由
  i18n,
  components: { App },
  template: '<App/>'
})

